jQuery(document).ready(function() { 

	var sidebarWidth = 280;		
	var $container = jQuery('.archives');
	
	$container.imagesLoaded( function(){		
		var winWidth = jQuery(window).width();		
		setColumnWidth();		
		$container.isotope({
				itemSelector : '.archives-post',
				resizable: false,
				transformsEnabled : false
		},function(){		
			if(jQuery(window).width() != winWidth) 
				setTimeout(function(){ arrange();},10);				
		});		
	});	
			
	function setColumnWidth(){
		var archiveWidth = 150;
		var winWidth = jQuery(window).width() ;		
		var leftOffset = sidebarWidth;		
		if(winWidth < 768) 	leftOffset = 0;		
		var containerWidth = winWidth - leftOffset;
		var columns =  Math.floor(containerWidth / archiveWidth);		
		var postWidth = containerWidth/columns;
		postWidth = Math.floor(postWidth) + 1; 		
		jQuery(".archives-post").each(function(index){
			jQuery(this).css({"width":postWidth+"px"});			
		});
	}
	
	function arrange(){
		var winWidth = jQuery(window).width();
		setColumnWidth();
		$container.isotope('reLayout',function(){
			if(jQuery(window).width() != winWidth) 
				setTimeout(function(){ arrange();},10);
		});		
	}
	
	jQuery(window).on("debouncedresize", function( event ) {
		arrange();		
	});	
	

});